﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GauntletFramework.SpriteManagment
{
    public class Sprite : DrawableGameComponent
    {
        public Sprite()
            : base(StaticGame.Game)
        {
            AnimationList = new Dictionary<string, SpriteSheetAnimation>();
        }

        public Dictionary<string, SpriteSheetAnimation> AnimationList;
        public SpriteSheetAnimation Current;

        public string GetAnimationName()
        {
            string name = "";
            try
            {
                name = AnimationList.First(x => x.Value == Current).Key;
            }
            catch (Exception ex) { }
            return name;
        }

        public void SetAnimation(string name)
        {
            try
            {
                Current = AnimationList[name];
                Current.Finished = false;
            }
            catch (Exception ex) { }
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            Current.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
        }

    }
}
